package com.blb.orderservice.controller;

import com.blb.common.entity.Order;
import com.blb.common.entity.ResponseResult;
import com.blb.orderservice.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Value("${spring.datasource.username}")
    private String username;

    @GetMapping("getUsername")
    public String getUsername(){
        return username;
    }

    @GetMapping("order/{id}")
    public ResponseResult<Order> getOrderById(@PathVariable Long id){
        Order order = orderService.getOrderById(id);
        return ResponseResult.ok(order);
    }
}
